package com.qingke.notlonely.command.system;

import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.qingke.notlonely.bean.User;
import com.qingke.notlonely.bean.Yue;
import com.qingke.notlonely.command.SystemCommand;
import com.qingke.notlonely.util.NLConsole;

public class ListYueByBeAccepted extends SystemCommand{

	@Override
	public void execute() {
		List<Yue> list=dao.selectYueByAccepted();
		Collections.sort(list,new Comparator<Yue>(){

			@Override
			public int compare(Yue o1, Yue o2) {
				String inviterName1=o1.getInviter().getName();
				String inviterName2=o2.getInviter().getName();
				
				Date time1=o1.getInviteTime();
				Date time2=o2.getInviteTime();
				
				String inviteeName1=o1.getInvitee().getName();
				String inviteeName2=o2.getInvitee().getName();
				
				if(!inviterName1.equals(inviterName2))
					return inviterName1.compareTo(inviterName2);
				
				if(time1.compareTo(time2)!=0)
					return time1.compareTo(time2);
				
				if(!inviteeName1.equals(inviteeName2))
					return inviteeName1.compareTo(inviteeName2);
					
				return 0;
			}
			
		});
		
		for(Yue y:list){
			User inviter=y.getInviter();
			User invitee=y.getInvitee();
			Date time=y.getInviteTime();
			
			String inviterStr="inviter [name]:"+inviter.getName()+",[gender]:"+inviter.getGender()+",[age]:"+inviter.getAge();
			String inviteeStr="invitee [name]:"+invitee.getName()+",[gender]:"+invitee.getGender()+",[age]:"+invitee.getAge();
			String timeStr=time.toString();
			
			NLConsole.println(inviterStr);
			NLConsole.println(inviteeStr);
			NLConsole.println(timeStr);
			NLConsole.println();
		}
	}

}
